package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.utils.AliOSSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

/**
 * @Author 山外小王
 * @Description
 * @Date 2024/04/15/17:10
 */
@RestController
@RequestMapping("/setmeal/upload")
public class AliyunOSSController {
    @Autowired
    private AliOSSUtils aliOSSUtils;
    @Autowired
    private StringRedisTemplate redisTemplate;
    public static final String ALL_IMG_FILE = "所有图片";//

    /**
     * 文件上传
     * @param imgFile
     * @return
     * @throws IOException
     */
    @PostMapping
    public Result upload(MultipartFile imgFile) throws IOException {
        String filePath = aliOSSUtils.upload(imgFile);
        //1.将用户上传的图片上传到Redis里
        redisTemplate.opsForSet().add(AliyunOSSController.ALL_IMG_FILE,filePath);
        return new Result(true, MessageConst.PIC_UPLOAD_SUCCESS,filePath);

    }

}
